package com.nursinghome.admin.controller;


import com.nursinghome.bean.RespBean;
import com.nursinghome.bean.Reservation;
import com.nursinghome.common.service.ReservationService;
import com.nursinghome.exception.NurisingHomeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/admin/reservation")
public class ReservationController {
    @Autowired
    private ReservationService reservationService;
    @GetMapping
    public RespBean selectAll(String pageNum, String pageSize, Reservation reservation) {

        return RespBean.ok("",reservationService.selectAll(pageNum, pageSize, reservation));
    }
    //新增预约服务订单
    @PostMapping
    public RespBean insert(@RequestBody Reservation reservation) throws NurisingHomeException {
        if (reservationService.insert(reservation)) {
            return RespBean.ok("新增成功");
        }
        return RespBean.error("新增失败");
    }
    //修改预约服务订单
    @PutMapping
    public RespBean update(@RequestBody Reservation reservation) throws NurisingHomeException {
        if (reservationService.update(reservation)) {
            return RespBean.ok("修改成功");
        }
        return RespBean.error("修改失败");
    }
    //删除预约服务订单
    @DeleteMapping("/{id}")
    public RespBean delete(@PathVariable("id") String id) throws NurisingHomeException {
        if (reservationService.delete(id)) {
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    //回显预约服务订单数据
    @GetMapping("/{id}")
    public RespBean selectById(@PathVariable("id") String id) throws NurisingHomeException {
        Reservation reservation = reservationService.selectById(id);
        return RespBean.ok("",reservation);
    }
}
